package com.ansorgit.helpful.configuration;

import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * User: jansorg
 * Date: Mar 22, 2010
 * Time: 9:09:19 PM
 */
public class SmartEditorConfigurable implements ApplicationComponent, Configurable {
    private SmartEditorSettings settings;

    @NotNull
    public String getComponentName() {
        return "SmarterEditorConfigurable";
    }

    public void initComponent() {
    }

    public void disposeComponent() {
        settings = null;
    }

    @Nls
    public String getDisplayName() {
        return "SmarterEditor";
    }

    public Icon getIcon() {
        return null;
    }

    public String getHelpTopic() {
        return null;
    }

    public JComponent createComponent() {
        if (settings == null) {
            settings = new SmartEditorSettings();
        }

        return settings.getRootPanel();
    }

    public boolean isModified() {
        return settings.isModified(SettingsManager.storedSettings());
    }

    public void apply() throws ConfigurationException {
        settings.storeIn(SettingsManager.storedSettings());
    }

    public void reset() {
        settings.reset(SettingsManager.storedSettings());
    }

    public void disposeUIResources() {
        settings = null;
    }
}
